<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>代理流水排行</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
<link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
<style>
.edit{background-color: #ed9c3a;}
.shenhe{background-color: #429488;}
.see{background-color: #7cb717;}
.tongbu{background-color: #4c9ef8;color:#fff;border-radius:3.5px}
.cur{color:#21c4f5;}
.userbox,.storebox{
  height:190px;margin-right:0;
  overflow-y: auto;
  z-index: 999;
  position: absolute;
  left: 0px;
  top: 63px;
  width:298px;
  background-color:#ffffff;
  border: 1px solid #ddd;
}
.userbox .list,.storebox .list{
  height:38px;line-height: 38px;cursor:pointer;
  padding-left:10px;
}
.userbox .list:hover,.storebox .list:hover{
  background-color:#eeeeee;
}
.yname{
  font-size: 13px;
  color: #444;
  margin-bottom:8px;
}
</style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12" style="margin-top:0px">
            <div class="layui-fluid">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header">代理流水排行</div>
                            <div class="layui-card-body">
                                <div class="layui-btn-container" style="font-size:14px;">
                                    <div style="font-size:14px">
                                        
                                        <div class="layui-form" lay-filter="component-form-group" style="width:190px;margin-right:0;display: inline-block;">
                                            <div class="layui-form-item">
                                                <div class="layui-input-block" style="margin-left:5px;border-radius:5px">
                                                    <text class="yname">代理商名称</text>
                                                    <input type="text" style="border-radius:5px"tyle="border-radius:5px" name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="请输入代理商名称" class="layui-input transfer">
                                                    <div class="userbox" style='display: none'></div>
                                                </div>
                                            </div>
                                        </div>
      
                                         <!-- 通道类型 -->
                                        <div class="layui-form" lay-filter="component-form-group" style="width:190px;margin-right:0;display: inline-block;">
                                          <div class="layui-form-item">
                                            <div class="layui-input-block" style="margin-left:5px;border-radius:5px">
                                            <text class="yname">订单开始时间</text>
                                                <input type="text" style="border-radius:5px" class="layui-input start-item test-item" placeholder="订单开始时间" lay-key="23">
                                            </div>
                                          </div>
                                        </div>
                                         <!-- 通道类型 -->
                                        <div class="layui-form" lay-filter="component-form-group" style="width:190px;margin-right:0;display: inline-block;">
                                          <div class="layui-form-item">
                                            <div class="layui-input-block" style="margin-left:5px;border-radius:5px">
                                             <text class="yname">订单结束时间</text>
                                                <input type="text" style="border-radius:5px" class="layui-input end-item test-item" placeholder="订单结束时间" lay-key="24">
                                            </div>
                                          </div>
                                        </div>
                                        <div class="layui-form" lay-filter="component-form-group" style="width:190px;margin-right:0;display: inline-block;">
                                          <div class="layui-form-item">
                                            <div class="layui-input-block" style="border-radius:5px">
                                             <button class="layui-btn layuiadmin-btn-list" lay-submit="" lay-filter="LAY-app-contlist-search" style="border-radius:5px;margin-top:0;margin-bottom: 0;height:36px;line-height: 36px;">
                                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                            </button>
                                            </div>
                                          </div>
                                        </div>
                                        <button class="layui-btn export" style="border-radius:5px;margin-bottom: 4px;height:36px;line-height: 36px;">导出</button>
                                        
                                    </div>
                                </div>

                                <table class="layui-hide" id="test-table-page" lay-filter="test-table-page"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input type="hidden" class="user_id">
<input type="hidden" class="company_id">

<script src="{{asset('/layuiadmin/layui/layui.js')}}"></script>
<script>
var token = localStorage.getItem("Usertoken");
var str=location.search;
var store_id=str.split('?')[1];

layui.config({
    base: '../../layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index','form','table','laydate'], function(){
    var $ = layui.$
        ,admin = layui.admin
        ,form = layui.form
        ,table = layui.table
        ,laydate = layui.laydate;

    $('.store_id').val(store_id);

    // 未登录,跳转登录页面
    $(document).ready(function(){
        if(token==null){
        window.location.href="{{url('/user/login')}}";
        }
    });

    var s_storename=localStorage.getItem('s_storename');

    if(store_id == undefined){

    }else{
        $('.inputstore').val(s_storename);
    }

    $(".transfer").bind("input propertychange",function(event){
        //         console.log($(this).val());
        user_name = $(this).val();
        if (user_name.length == 0) {
            $('.userbox').html('');
            $('.userbox').hide();
            $('.user_id').val('')
        } else {
            $.post("{{url('/api/user/get_sub_users')}}",
            {
                token:token
                ,user_name:$(this).val()
                ,self:'1'
            },function(res){
                var html="";

                if(res.t==0){
                    $('.userbox').html('');
                }else{
                    for(var i=0;i<res.data.length;i++){
                        html+='<div class="list" data='+res.data[i].id+'>'+res.data[i].name+'-'+res.data[i].level_name+'</div>'
                    }
                    $(".userbox").show();
                    $('.userbox').html('');
                    $('.userbox').append(html);
                }
            },"json");
        }
    });

    $(".userbox").on("click",".list",function(){
        $('.transfer').val($(this).html());
        $('.user_id').val($(this).attr('data'));
        $('.userbox').hide();

        // table.reload('test-table-page', {
        //     where: {
        //         user_id:$(this).attr('data'),
        //         store_id:$('store_id').val()
        //     }
        //     ,page: {
        //         curr: 1
        //     }
        // });
    });

    // 渲染表格
    table.render({
        elem: '#test-table-page'
        ,url: ""
        ,method: 'post'
        ,where:{
            token:token
            ,store_id:store_id
        }
        ,request:{
            pageName: 'p'
            ,limitName: 'l'
        }
        ,page: true
        ,cellMinWidth: 100
        ,cols: [[
            {field:'user_id',align:'center',title: '代理商id'},
            {field:'user_name',align:'center',title: '姓名'}
           ,{field:'total_amount',align:'center',title: '交易总额'}
        ]]
        ,response: {
            statusName: 'status' //数据状态的字段名称，默认：code
            ,statusCode: 1 //成功的状态码，默认：0
            ,msgName: 'message' //状态信息的字段名称，默认：msg
            ,countName: 't' //数据总数的字段名称，默认：count
            ,dataName: 'data' //数据列表的字段名称，默认：data
        }
        ,done: function(res, curr, count){
//            console.log(res);
            $('th').css({'font-weight': 'bold', 'font-size': '15','color': 'black','background':'linear-gradient(#f2f2f2,#cfcfcf)'});	//进行表头样式设置
        }
    });

    laydate.render({
        elem: '.start-item'
        ,type: 'date'
        ,done: function(value){
            //执行重载
            // table.reload('test-table-page', {
            //     where: {
            //         time_start:value
            //         ,time_end:$('.end-item').val()
            //     }
            //     ,page: {
            //         curr: 1 //重新从第 1 页开始
            //     }
            // });
        }
    });

    laydate.render({
        elem: '.end-item'
        ,type: 'date'
        ,done: function(value){
            //执行重载
            // table.reload('test-table-page', {
            //     where: {
            //         time_start:$('.start-item').val()
            //         ,time_end:value
            //     }
            //     ,page: {
            //         curr: 1 //重新从第 1 页开始
            //     }
            // });
        }
    });

    form.on('submit(LAY-app-contlist-search)', function(data){
        var pageLoading = layer.msg('数据请求中..', {
            icon: 16
            ,shade: 0.3
            ,time: false
        });
        table.reload('test-table-page', {
            url: "{{url('/api/user/user_trade_rank')}}",
            where: {
              time_start: $('.start-item').val(),
              time_end: $('.end-item').val(),
              user_id: $('.user_id').val(),
            }
            ,page: {
              curr: 1 //重新从第 1 页开始
            },
            done:function(res, curr, count){
                layer.close(pageLoading);
            }
         });
    });
    
    $('.export').click(function(){
        var user_id = $('.user_id').val();//3
        var time_start = $('.start-item').val();//1
        var time_end = $('.end-item').val();//2
        window.location.href="{{url('/api/export/user_trade_rank_ExcelDown')}}"+"?token="+token+"&user_id="+user_id+"&time_start="+time_start+"&time_end="+time_end;
    })
});

</script>

</body>
</html>
